package com.mmall.concurrency.example.threadPool;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

@Slf4j
public class ThreadPoolExample7 {

    public static void main(String[] args) throws Exception{
        ExecutorService service = Executors.newCachedThreadPool();

//        for (int i = 0; i < 100; i++) {
//            final int num = i;
//            service.submit(() -> {
//                System.out.println(num);
//            });
//        }

        for (int i = 0; i < 100; i++) {
            final int num = i;
            Future<Integer> future = service.submit(() -> {
               return num + 1;
            });
            System.out.println(future.get());
        }

        service.shutdown();

    }
}
